﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Windows;
using System.Windows.Controls;
using Majesty_of_Omega.Logic.GameConfiguration;
using Majesty_of_Omega.Config;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Setup
{
    /// <summary>
    /// Code Behind class for the race Pick Page
    /// </summary>
    /// <remarks>
    /// In the race pick page, the user can customize and change all race settings. the total
    /// sum of all changes must be 0.
    /// </remarks>
    public partial class Step2_RacePickPage
    {
        /// <summary>
        /// Construct the code behind
        /// </summary>
        public Step2_RacePickPage()
        {
            InitializeComponent();
            LayoutRoot.DataContext = GameConfigurator.GameSettings;
            SetRacePickItemsControlSource();
        }

        #region OnRaceChanged handlers

        /// <summary>
        /// The user has clicked on a RacePickSetting (like Bioharvesting). We fill the RaceModifiers Listbox
        /// </summary>
        private void RacePickSettingListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (RacePickItemsControl != null)
            {
                SetRacePickItemsControlSource();
            }
        }

        private void SetRacePickItemsControlSource()
        {
            RacePickItemsControl.ItemsSource =
                GameConfigurator.GameRaceConfigurator.ChangedModifiersForRacePickSetting(
                    (RaceModifiersRacePickSetting) RacePickSettingListBox.SelectedValue);
        }

        /// <summary>
        /// The user change a race pick. The race configurator modifies the race attributes.
        /// </summary>
        private void RacePickRadioButton_Click(object sender, RoutedEventArgs e)
        {
            string modifier = (string) ((RadioButton) sender).Tag;
            GameConfigurator.GameRaceConfigurator.ChangeRacePick(
                ((RaceModifiersRacePickSetting) RacePickSettingListBox.SelectedValue).Name, modifier);
        }

        #endregion
    }
}